<template>
<uni-shadow-root class="partials-activitiesGoods-activitiesGoods"><import src="simpleActivitiesGoods.wxml"></import>  
<import src="column_promotion_list/column_promotion_list.wxml"></import>  
<import src="pupuPromotionList/index.wxml"></import>  
<import src="pupuPromotionDetailList/index.wxml"></import>  
<block v-if="data.androidTemplate == """>
    <template is="simpleActivitiesGoods" :data="...data,countDownDay,countDownHour,countDownMinute,countDownSecond,setting"></template> 
</block> 
<block v-if="data.androidTemplate == "column_promotion_list"">
    <template is="column_promotion_list" :data="...data,countDownDay,countDownHour,countDownMinute,countDownSecond,setting"></template> 
</block> 
<block v-if="data.androidTemplate == "pupu_promotion_list"">
    <template is="pupuPromotionList" :data="...data,countDownDay,countDownHour,countDownMinute,countDownSecond,setting"></template> 
</block> 
<block v-if="data.androidTemplate == "pupu_promotion_detail_list"">
    <template is="pupuPromotionDetailList" :data="...data,countDownDay,countDownHour,countDownMinute,countDownSecond,setting"></template> 
</block></uni-shadow-root>
</template>

<script>

global['__wxRoute'] = 'partials/activitiesGoods/activitiesGoods'
const app = getApp();
Component({
  properties: {
    data: {
      type: JSON,
      value: 'default value',
    }
  },
  data: {
    someData: {},
    color:"",
    countDownDay: "",
    countDownHour: "",
    countDownMinute: "",
    countDownSecond: "",
    setting:{},
  },
  ready: function (options) {
    var that=this;
    var oldData = that.data;
    app.globalData.consoleFun("=====activitiesGoods组件-导航=====",[that.data.data])
    that.setData({ setting: app.globalData.setting.platformSetting})
    if (oldData.data.relateBean.promotionStatus == 1) {
      var interval = setInterval(function () {
        var t1 = oldData.data.relateBean.endDate;
        var d1 = t1.replace(/\-/g, "/");
        var date1 = new Date(d1);
        var totalSecond = parseInt((date1 - new Date()) / 1000);
        var second = totalSecond;
        var day = Math.floor(second / 3600 / 24);
        var dayStr = day.toString();
        if (dayStr.length == 1) dayStr = '0' + dayStr;
        var hr = Math.floor((second - day * 3600 * 24) / 3600);
        var hrStr = hr.toString();
        if (hrStr.length == 1) hrStr = '0' + hrStr;
        var min = Math.floor((second - day * 3600 * 24 - hr * 3600) / 60);
        var minStr = min.toString();
        if (minStr.length == 1) minStr = '0' + minStr;
        var sec = second - day * 3600 * 24 - hr * 3600 - min * 60;
        var secStr = sec.toString();
        if (secStr.length == 1) secStr = '0' + secStr;
        this.setData({
          countDownDay: dayStr,
          countDownHour: hrStr,
          countDownMinute: minStr,
          countDownSecond: secStr,
        });
        totalSecond--;
        if (totalSecond < 0) {
          clearInterval(interval);
          wx.showToast({
            title: '活动已结束',
          });
          this.setData({
            countDownDay: '00',
            countDownHour: '00',
            countDownMinute: '00',
            countDownSecond: '00',
          });
        }
      }.bind(this), 1000);
    }
    if (oldData.data.relateBean.promotionStatus == 0) {
      var interval = setInterval(function () {
        var t1 = oldData.data.relateBean.startDate;
        var d1 = t1.replace(/\-/g, "/");
        var date1 = new Date(d1);
        var totalSecond = parseInt((date1 - new Date()) / 1000);
        var second = totalSecond;
        var day = Math.floor(second / 3600 / 24);
        var dayStr = day.toString();
        if (dayStr.length == 1) dayStr = '0' + dayStr;
        var hr = Math.floor((second - day * 3600 * 24) / 3600);
        var hrStr = hr.toString();
        if (hrStr.length == 1) hrStr = '0' + hrStr;
        var min = Math.floor((second - day * 3600 * 24 - hr * 3600) / 60);
        var minStr = min.toString();
        if (minStr.length == 1) minStr = '0' + minStr;
        var sec = second - day * 3600 * 24 - hr * 3600 - min * 60;
        var secStr = sec.toString();
        if (secStr.length == 1) secStr = '0' + secStr;
        this.setData({
          countDownDay: dayStr,
          countDownHour: hrStr,
          countDownMinute: minStr,
          countDownSecond: secStr,
        });
        totalSecond--;
        if (totalSecond < 0) {
          clearInterval(interval);
          this.setData({
            countDownDay: '00',
            countDownHour: '00',
            countDownMinute: '00',
            countDownSecond: '00',
          });
        }
      }.bind(this), 1000);
    }
  },
  methods: {
    tolinkUrl: function (event) {
      app.globalData.linkEvent(event.currentTarget.dataset.link);
    },
    clickLink: function (e) {
      console.log(e)
      var oldData = this.data;
      if (oldData.data.relateBean.promotionStatus == 1) {
        console.log("=====已开始的活动========")
        var a = "product_detail.html?productId=" + e.currentTarget.dataset.id;
        app.globalData.linkEvent(a);
      }else if (oldData.data.relateBean.promotionStatus == 0) {
        console.log("=====未开始的活动========")
        var a = "promotion_detail.html?promotionId=" + e.currentTarget.dataset.id;
        app.globalData.linkEvent(a);
      }else if (oldData.data.relateBean.promotionStatus == 2) {
        console.log("=====已结束的活动========")
        var a = "product_detail.html?productId=" + e.currentTarget.dataset.id;
        app.globalData.linkEvent(a);
      }
    },
    clickLink1: function (e) {
      var oldData = this.data;
      if (oldData.data.relateBean.promotionStatus == 1) {
        wx.navigateTo({
          url: '../../pageTab/tunzai/teMai/index?promotionId=' + e.currentTarget.dataset.id,
        })
      }
      if (oldData.data.relateBean.promotionStatus == 0) {
        var a = "promotion_detail.html?promotionId=" + e.currentTarget.dataset.id;
        app.globalData.linkEvent(a);
      }
    },
  },
})
export default global['__wxComponents']['partials/activitiesGoods/activitiesGoods']
</script>
<style platform="mp-weixin">
@import 'column_promotion_list/column_promotion_list.css';
@import 'pupuPromotionList/index.css';
@import 'pupuPromotionDetailList/index.css';
.recommend_scroll_x_box {
  height: 242rpx;
  white-space: nowrap;
  display: flex;
}
.mt20{
  margin-top: 20rpx;
}
.recommend_hot_box {
  width: 222rpx;
  height: 222rpx;
  margin-left: 24rpx;
  display: inline-block;
  text-align: center;
  position: relative;
}
.recommend_hot_box_copy{
  width: 222rpx;
  height: 230rpx;
  margin-left: 24rpx; 
  display: inline-block;
  text-align: center;
  position: relative;
  top: -100rpx; 
}
.recommend_hot_box_copy text{
  font-size: 32rpx;
  line-height: 222rpx;
}
.CouponsImg {
  width: 222rpx;
  height: 222rpx;
  overflow: hidden;
}
.CouponsImg image{
  width: 100%;
  height: 100%;
}
.choose{
  width: 100rpx;
  height: 50rpx;
  position: absolute;
  right: 5rpx;
  bottom: 15rpx;
  background-color: #FE313C;
  z-index: 1000;
  text-align: center;
  border-radius: 20rpx;
}
.choose text{
  display: block;
  font-size: 24rpx;
  line-height: 50rpx;
  color: white;
}
.footer{
  width: 750rpx;
  height: 80rpx;
  background: linear-gradient(to right, #F44 , #FF8B8B);
  margin-top: 30rpx;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}
.activeName{
  width: 280rpx;
  height: 80rpx;
  text-align: left;
  overflow:hidden; 
  text-overflow:ellipsis;
  white-space:nowrap;
}
.activeName text{
    font-size: 40rpx;
    line-height: 80rpx;
    color: white;
    margin-left: 10rpx;
}
.time{
  width: 450rpx;
  height: 80rpx;
  display: flex;
  flex-direction: row;
}
.timeText{
  text-align: center;
  margin-right: 5rpx;
}
.timeText text{
  font-size: 28rpx;
  line-height: 80rpx;
  color: white;
}
.timeBox{
  width: 60rpx;
  height: 40rpx;
  background-color: white;
  margin-top: 20rpx;
  text-align: center;
  margin-right: 10rpx;
  border-radius: 10rpx;
}
.timeBox text{
  display: block;
  font-size: 20rpx;
  line-height: 40rpx;
}
</style>